/**
 * 用户信息添加编辑窗体
 */
group.win = group.win || Ext.extend(Ext.Window,{
	initComponent:function(){
		Ext.apply(this, {
			resizable : false,																					
			animateTarget : document.body,																		
			closeAction: 'hide',																				
			plain: true,
			modal: true,
			width: 400,
			items:this.getForm()
		}),
		group.win.superclass.initComponent.call(this);
	},
	getForm : function(){
		return {
        	xtype:'form',
            bodyStyle:'padding:10px',
            labelWidth : 80,
            defaults : {
            	width : 260	
            },
            defaultType:'textfield',
            border:false,
            items:[{
                fieldLabel:'组名',
                blankText : '组名不能为空,请输入!',
                allowBlank:false,
                maxLength : 20,
                maxLengthText : '组名的最大长度为20个字符',	
                name:'groupName'
            },{
                xtype:'hidden', 
                name:'id',
                value:'0',
        	    anchor:'90%'
            },new Ext.ux.ComboBoxTree({																		
				fieldLabel : '上级组名',																			
				hiddenName : 'parentName',																		
				allowBlank : false,																			
				blankText : '上级组名不能为空,请输入!',																
				tree : new Ext.tree.TreePanel({																
					rootVisible:false,																			
					loader: new Ext.tree.TreeLoader({														
						dataUrl:'group/getGroupTree.jhtml' ,														
						clearOnLoad: true,																	
						listeners: {																		
							'beforeload': function(treeloader, node) {										
								treeloader.baseParams = {													
									id: node.id,															
									method: 'POST'															
								};																			
							}																				
						}																					
					}),																						
				 	root : new Ext.tree.AsyncTreeNode({id:'0',text:'根结点'})									
				 }), 																						
				 selectNodeModel:'leaf', 																	
				 listeners:{'afterchange':function(lnode,n,o){Ext.getCmp('group_id').setValue(n.id);}}
			}),{																							
				xtype:'hidden', 
                name:'parentId',
                id:'group_id'
			},{																							
				fieldLabel:'组描述',
                maxLength : 30,
                maxLengthText : '组描述的最大长度为30个字符',	
                name:'groupDesc'																		
				}],																								
			buttons : [{																						
				text : '保存',																					
				iconCls : 'save',																				
				handler : group.save
			},{																									
				text : '重置',																					
				iconCls : 'refresh',																				
				handler :group.reset																						
			}]	
        };
	}
});

//保存数据
group.save = function(){
	var win = this.ownerCt.ownerCt.ownerCt;//当前win
	var form = this.ownerCt.ownerCt.form;																						
  	var groupId = this.ownerCt.ownerCt.findByType('hidden')[0].getValue();											
	var url = groupId==0?'group/addGroup.jhtml':'group/modGroup.jhtml';												
	if (form.isValid()) {																					
		form.submit({																						
			url : url,																						
			waitTitle : '提示',																				
			method : 'POST',																				
			waitMsg : '正在提交数据,请稍候.....',																	
			success : function(form, action) {																
				Ext.Msg.alert('提示',action.result.msg, function() {											
					win.hide();
					Ext.getCmp(group.parentId).items.get(0).store.reload();//刷新grid
				});																							
			},																								
			failure : function(form, action) {																
				Ext.Msg.alert('提示',action.result.msg, function() {											
					form.reset();
				});																							
			}																								
		});																									
	}			
};

//清空表单
group.reset = function(){
	var win_form = this.ownerCt.ownerCt;
	win_form.form.reset();
};

//角色树
group.roleWin = group.roleWin || Ext.extend(Ext.Window,{
	initComponent:function(){
		Ext.apply(this, {
			resizable : false,																					
			animateTarget : document.body,																		
			closeAction: 'hide',																				
			plain: true,
			modal: true,
			width: 230,
			height: 450,
			items:this.getTree(),
			buttons : [{
				text : '保存',																					
				iconCls : 'save',																				
				handler : this.close
			},{																									
				text : '关闭',																					
				iconCls : 'close',																				
				handler :this.close
			}]
		}),
		group.roleWin.superclass.initComponent.call(this);
	},
	getTree:function(){
		return {
			xtype:'treepanel',
			height: 448,
			root : new Ext.tree.AsyncTreeNode({
				id : '0',
				text :'根节点',
				expanded : true
			}),
			rootVisible:false,
			loader : new Ext.tree.TreeLoader({
				baseAttrs : {},
				dataUrl : 'role/getRoleCheckBoxTree.jhtml',
				listeners: {
					'beforeload':function(treeloader, node) {
						treeloader.baseParams = {
							id: node.id,
							method: 'POST'
						};
					}
				}
			}),
			autoScroll : true,
			listeners:{
            "checkchange": function(node, checked) {
            	node.expand();   
				node.attributes.checked = checked;   
				node.eachChild(function(child) {   
					child.ui.toggleCheck(checked);   
					child.attributes.checked = checked;   
					child.fireEvent('checkchange', child, checked);   
				});
            }
        }
	  };
	}
});